﻿Imports System.Data
Imports System.Data.SqlClient
Public Class DALRecurso
    Dim cmd As SqlCommand
    Dim ret As Boolean
#Region "Recurso"
    Function Inserir(ByVal descricao As String, ByVal patrimonio As String, ByVal obs As String, ByVal status As String, ByVal motivo As String, ByVal datacad As String)
        Try
            cmd = New SqlCommand
            cmd.CommandText = "execute sp_Recurso @descricao,@patrimonio,@obs,@status,@motivo,@datacad,@codigo;"
            cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.VarChar)).Value = descricao
            cmd.Parameters.Add(New SqlParameter("@patrimonio", SqlDbType.VarChar)).Value = patrimonio
            cmd.Parameters.Add(New SqlParameter("@obs", SqlDbType.VarChar)).Value = obs
            cmd.Parameters.Add(New SqlParameter("@status", SqlDbType.VarChar)).Value = status
            cmd.Parameters.Add(New SqlParameter("@motivo", SqlDbType.VarChar)).Value = motivo
            cmd.Parameters.Add(New SqlParameter("@datacad", SqlDbType.VarChar)).Value = datacad
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = 0
            ret = objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw ex
        End Try
        Return ret
    End Function

    Function localizar(ByVal Codigo As Integer) As DataTable
        Dim cmd As SqlCommand
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select rec_codigo,rec_descricao,rec_patrimonio,rec_obs,rec_status,rec_motivo,rec_datacad,rec_estado from  age_recurso where " & _
                " rec_codigo = @codigo and rec_estado='A' and rec_status <> 'Desativado'"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = Codigo
            tab = objconAgenda.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
    Function localizar(ByVal Descricao As String) As DataTable
        Dim cmd As SqlCommand
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select rec_codigo,rec_descricao,rec_patrimonio,rec_status,rec_motivo,rec_obs,rec_datacad,rec_estado from  age_recurso where " & _
                " rec_descricao like @descricao and rec_estado='A'"
            cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.VarChar)).Value = "%" & Descricao & "%"
            tab = objconAgenda.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
    Function localizarTudo() As DataTable
        Dim cmd As SqlCommand
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select rec_codigo,rec_descricao,rec_patrimonio,rec_status,rec_motivo,rec_obs,rec_datacad,rec_estado from  age_recurso  " & _
                "where rec_estado='A' order by rec_descricao"
            tab = objconAgenda.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
    Function ValidaDuplicata(ByVal Patrimonio As String, ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from age_recurso where rec_patrimonio = @patrimonio and rec_estado='A' and rec_codigo <> @codigo;"
            cmd.Parameters.Add(New SqlParameter("@patrimonio", SqlDbType.VarChar)).Value = Patrimonio
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            tab = objconAgenda.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
    Function ValidaExclusao(ByVal Codigo As Integer) As DataTable
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from vw_AgendamentoRecurso where rec_codigo = @codigo;"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = Codigo
            tab = objconAgenda.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
    Function Excluir(ByVal codigo As Integer) As Integer
        Dim cmd As SqlCommand
        Dim ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "delete from age_recurso where rec_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            ret = objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return ret
    End Function
    Function ExcluirUpdate(ByVal codigo As Integer) As Integer
        Dim cmd As SqlCommand
        Dim ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "update age_recurso set rec_estado='I'" & _
                " where rec_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            ret = objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return ret
    End Function
    Function Alterar(ByVal descricao As String, ByVal patrimonio As String, ByVal obs As String, ByVal status As String, ByVal motivo As String, ByVal datacad As String, ByVal codigo As Integer) As Integer
        Dim cmd As SqlCommand
        Dim ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "execute sp_Recurso @descricao,@patrimonio,@obs,@status,@motivo,@datacad,@codigo;"
            cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.VarChar)).Value = descricao
            cmd.Parameters.Add(New SqlParameter("@patrimonio", SqlDbType.VarChar)).Value = patrimonio
            cmd.Parameters.Add(New SqlParameter("@obs", SqlDbType.VarChar)).Value = obs
            cmd.Parameters.Add(New SqlParameter("@status", SqlDbType.VarChar)).Value = status
            cmd.Parameters.Add(New SqlParameter("@motivo", SqlDbType.VarChar)).Value = motivo
            cmd.Parameters.Add(New SqlParameter("@datacad", SqlDbType.VarChar)).Value = datacad
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            ret = objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return ret
    End Function
#End Region
End Class
